package com.beijiteshop.shop.ui.main

import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import androidx.lifecycle.lifecycleScope
import com.beijiteshop.libcommon.base.activity.BaseActivity
import com.beijiteshop.libcommon.login.UserInfoUtil
import com.beijiteshop.libcommon.utils.DensityUtil
import com.beijiteshop.shop.R
import com.beijiteshop.shop.databinding.ActivitySplashBinding
import com.beijiteshop.shop.ui.login.LoginActivity
import com.blankj.utilcode.util.LogUtils
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class SplashActivity : BaseActivity<ActivitySplashBinding>() {

    override fun onCreate(savedInstanceState: Bundle?) {
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN)
        super.onCreate(savedInstanceState)
    }

    override fun getLayoutRes(): Int = R.layout.activity_splash

    override fun initView(savedInstanceState: Bundle?) {

        lifecycleScope.launch {
            LogUtils.dTag("TAG","token:${UserInfoUtil.getInstance().getLoginInfo()?.token}")
            delay(2000)
            if (UserInfoUtil.getInstance().isLogin()){
                startActivity(Intent(this@SplashActivity,MainActivity::class.java))
            }else{
                startActivity(Intent(this@SplashActivity,LoginActivity::class.java))
            }
            finish()
        }
    }

    override fun initData() {
    }

    override fun initEvent() {
    }

    override fun onBackPressed() {

    }
}